<%--
  Created by IntelliJ IDEA.
  User: 86157
  Date: 2025/6/5
  Time: 20:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>Title</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  </head>
  <body>
  <form  action="${pageContext.request.contextPath}/register" method="post">
    <input type="text" name="name"><br>
    <input type="text" name="password"><br>
    <input type="submit" value="提交">
  </form>
  <form  action="${pageContext.request.contextPath}/getUserMajor" method="post">
    <input type="text" name="name"><br>
    <input type="text" name="major.name"><br>
    <input type="submit" value="提交">
  </form>
  <form  action="${pageContext.request.contextPath}/bindArray" method="post">
    <table>
      <tr>
        <td>选择</td>
        <td>姓名</td>
      </tr>
      <tr>
        <td>
          <input type="checkbox" name="names" value="安特卫普">
        </td>
        <td>
          安特卫普
        </td>
      </tr>
      <tr>
        <td>
          <input type="checkbox" name="names" value="斯德哥尔摩">
        </td>
        <td>
          斯德哥尔摩
        </td>
      </tr>
      <tr>
        <td>
          <input type="checkbox" name="names" value="柏林">
        </td>
        <td>
          柏林
        </td>
      </tr>
    </table>
    <input type="submit" value="提交">
  </form>
  <form  action="${pageContext.request.contextPath}/bindList" method="post">
    <table>
      <tr>
        <td>选择</td>
        <td>姓名</td>
      </tr>
      <tr>
        <td>
          <input type="checkbox" name="names" value="安特卫普">
        </td>
        <td>
          安特卫普
        </td>
      </tr>
      <tr>
        <td>
          <input type="checkbox" name="names" value="斯德哥尔摩">
        </td>
        <td>
          斯德哥尔摩
        </td>
      </tr>
      <tr>
        <td>
          <input type="checkbox" name="names" value="柏林">
        </td>
        <td>
          柏林
        </td>
      </tr>
    </table>
    <input type="submit" value="提交">
  </form>
  <form id="majors">
    <table border="1">
      <tr>
        <th>id</th>
        <th>name</th>
      </tr>
      <tr>
        <td>
          <input type="text" name="id" value="1" id="id1">
        </td>
        <td>
          <input type="text" name="names" value="安特卫普" id="name1">
        </td>
      </tr>
      <tr>
        <td>
          <input type="text" name="id" value="2" id="id2">
        </td>
        <td>
          <input type="text" name="names" value="斯德哥尔摩" id="name2">
        </td>
      </tr>
      <tr>
        <td>
          <input type="text" name="id" value="3" id="id3">
        </td>
        <td>
          <input type="text" name="names" value="柏林" id="name3">
        </td>
      </tr>
    </table>
    <input type="button" value="提交" onclick="submitMajor()">
    <input type="button" value="提交" onclick="submitMajors()">
  </form>
  </body>
  <script type="text/javascript">
    function submitMajor() {
      var id =$("#id1").val();
      var name =$("#name1").val();
      $.ajax({
        url:"${pageContext.request.contextPath}/bindMajor",
        type:"post",
        data:JSON.stringify({
          id:id,
          name:name
        }),
        contentType:"application/json;charset=utf-8",
        dataType:"json",
        success:function (data) {
          alert(data);
        }
      })
    }
  </script>
  <script type="text/javascript">
    function submitMajors() {
      var major1 = {id:  $("#id1").val(), name: $("#name1").val()}
      var major2 = {id:  $("#id2").val(), name: $("#name2").val()}
      $.ajax({
        url:"${pageContext.request.contextPath}/bindMajors",
        type:"post",
        data:JSON.stringify([major1,major2]),
        contentType:"application/json;charset=utf-8",
        dataType:"json",
        success:function (data) {
          alert(data);
        }
      })
    }
  </script>
</html>
